﻿using Rabbit.Common;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rabbit.Provider.Helloword
{
    //Helloword模型 基本模型
    internal class SendHelloword
    {
        /// <summary>
        /// 发送消息
        /// </summary>
        //public static async void SendHellowordMsgAsync() 
        //{
        ////创建连接
        //using (var conn = RabbitMQHelper.GetConnect())
        //{
        //    //创建信道
        //    using (var channel = conn.CreateModel())
        //    {
        //        //创建队列
        //    }

        //}
        //string qName = "HwQue";//队列名称
        ////创建连接
        //using var connection = await RabbitMQHelper.GetConnect();
        ////创建信道
        //using var channel = await connection.CreateChannelAsync();
        ////创建队列
        //await channel.QueueDeclareAsync(queue: qName, durable: false, exclusive: false, autoDelete: false,arguments: null);

        //int i = 0;
        //while (i<10)
        //{ 
        //   //如果是集合先序列化成json数组
        //    string content = $"Helloword,这事第{i}条 ";
        //    byte[] body = Encoding.UTF8.GetBytes(content);
        //    await channel.BasicPublishAsync(exchange: string.Empty, routingKey: qName,  body: body);//交换机，路由(队列)，内容
        //    Console.WriteLine($"发送第{i}条完毕");
        //    i++;
        //}

        //}


        /// <summary>
        /// 发送消息
        /// </summary>
        public static void SendHellowordMsg()
        {
            string qName = "HwQue";//队列名称
            //创建连接
            using (var conn = RabbitMQHelper.GetConnect())
            {
                //创建信道
                using (var channel = conn.CreateModel())
                {
                    //创建队列
                    channel.QueueDeclare(qName, false, false, false, null);

                    int i = 0;
                    while (i < 10)
                    {
                        //如果是集合先序列化成json数组
                        string content = $"hello，这是第{i}条";
                        byte[] body = Encoding.UTF8.GetBytes(content);
                        channel.BasicPublish(exchange: "", routingKey: qName, null, body);
                        Console.WriteLine($"发送第{i}条完毕");
                        i++;
                    }
                }
            }
        }



    }
}
